package com.kingint.web.admin.serve.controller;


import com.kingint.mbg.dto.BackQueryParam;
import com.kingint.mbg.dto.servcieOrder.SerServiceOrderParam;
import com.kingint.mbg.group.Insert;
import com.kingint.mbg.ser.entity.SerServiceOrder;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.kingint.web.portal.serve.service.ServiceOrderService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.kingint.common.unitedresult.K;
import com.kingint.web.admin.serve.service.SerServiceOrderService;

import javax.annotation.Resource;


/**
 * @描述：服务工单表控制类
 * @作者: wxh
 * @日期: 2020-12-28
 */
@RestController
@RequestMapping("/serServiceOrder")
@Api(value = "SerServiceOrderController", description = "服务工单表")
@CrossOrigin
public class SerServiceOrderController {

    @Resource
    public SerServiceOrderService serServiceOrderService;
    @Resource
    private ServiceOrderService serviceOrderService;


    @ApiOperation(value = "添加服务工单表")
    @PostMapping("/create")
    public Object create(@RequestBody SerServiceOrder serServiceOrder) {
        Integer i = serServiceOrderService.insertServiceInfo(serServiceOrder);
        if (i > 0) {
            return K.ok().data(serServiceOrder.getId());
        } else {
            return K.error();
        }
    }

    @ApiOperation(value = "删除服务工单表")
    @DeleteMapping("/delete/{id}")
//    @PreAuthorize("hasAuthority('serServiceOrder:delete')")
    public Object delete(@PathVariable("id") Integer id) {
        int i = serServiceOrderService.deleteServiceOrderInfo(id);
        if (i > 0) {
            return K.ok();
        } else {
            return K.error();
        }
    }

    @ApiOperation(value = "根据服务工单表名称分页获取服务工单表列表")
    @GetMapping("/list")
//    @PreAuthorize("hasAuthority('serServiceOrder:list')")
    public Object getList(BackQueryParam queryParam,
                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                          @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        IPage<SerServiceOrderParam> serviceOrderList = serServiceOrderService.getServiceOrderList(queryParam, pageNum, pageSize);
        return K.ok().data(serviceOrderList);
    }

    @ApiOperation(value = "根据编号查询服务工单表信息")
    @GetMapping("/{id}")
//    @PreAuthorize("hasAuthority('serServiceOrder:get')")
    public Object getItem(@PathVariable("id") Integer id) {
        SerServiceOrderParam serviceOrderInfo = serServiceOrderService.getServiceOrderInfo(id);
        return K.ok().data(serviceOrderInfo);
    }

    @ApiOperation(value = "挂起此单")
    @GetMapping("/hangUpOrder")
    public Object hangUpOrder(@RequestParam(value = "id") Integer id) {
        int i=serviceOrderService.hangUpOrder(id);
        if(i>0){
            return K.ok().data(i);
        }
        return K.error();
    }
    //更换处理人
    @ApiOperation(value = "更换处理人")
    @GetMapping("/changeHandleUser")
    public Object changeHandleUser(@RequestParam(value = "id") Integer id,@RequestParam("memberId") Long memberId) {
        int i=serviceOrderService.changeHandleUser(id,memberId);
        if(i>0){
            return K.ok().data(i);
        }
        return K.error();
    }
}